import java.awt.Point;
import java.util.ArrayList;
import java.util.Map;

import com.speljohan.rsbot.script.Constants;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.RSInterface;

public class getEquipmentArray extends Script {

	public getEquipmentArray() {
		super();
		setParameter("author", "test");
		setParameter("version", "1");
		setParameter("name", "test");
		setParameter("category", "Combat");
	}

	int helm;
	int cape;
	int amulet;
	int weapon;
	int body;
	int shield;
	int legs;
	int gloves;
	int boots;
	int ring;
	int arrows;

	String eqarray1 = "cape";
	String eqarray2 = "amulet";
	String eqarray3 = "weapon";
	String eqarray4 = "body";
	String eqarray5 = "shield";
	String eqarray6 = "-1";
	String eqarray7 = "legs";
	String eqarray8 = "-1";
	String eqarray9 = "gloves";
	String eqarray10 = "boots";
	String eqarray11 = "-1";
	String eqarray12 = "ring";
	String eqarray13 = "arrows";
	String eqarray14 = "-1";

	boolean spec = false;

	public String getName() {
		return "test";
	}

	public String getAuthor() {
		return "test";
	}

	public String getScriptCategory() {
		return "Combat";
	}

	public double getVersion() {
		return 1;
	}

	public boolean onStart(Map<String, String> args) {
		helm = getEquipmentArray()[0];
		cape = getEquipmentArray()[1];
		amulet = getEquipmentArray()[2];
		weapon = getEquipmentArray()[3];
		body = getEquipmentArray()[4];
		shield = getEquipmentArray()[5];
		legs = getEquipmentArray()[7];
		gloves = getEquipmentArray()[9];
		boots = getEquipmentArray()[10];
		ring = getEquipmentArray()[12];
		arrows = getEquipmentArray()[13];
		return true;
	}

	public void useDDS() {
		int DDS = 13468;
		if (equipmentContainsAny(DDS)) {
			if (getCurrentTab() != TAB_ATTACK) {
				openTab(TAB_ATTACK);
			}
			wait(random(600, 1200));
			try {
				if (getSpec() >= 1000 && !specEnabled() && spec == true) {
					openTab(Constants.TAB_ATTACK);
					clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
					wait(400);
					clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
					wait(400);
					clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
					wait(400);
					clickMouse(645 + random(0, 4), 425 + random(0, 4), true);
					wait(400);
				}
			} catch (Exception e) {

			}
		}
		return;
	}

	public void switchArmour(int helm, int body, int legs, int weapon) {
		if (inventoryContainsAny(helm, body, legs, weapon)) {
			if (getCurrentTab() != TAB_INVENTORY) {
				openTab(TAB_INVENTORY);
			}
			wait(random(600, 1200));
			try {
				openTab(Constants.TAB_INVENTORY);
				clickInventoryItem(helm, "Wear");
				wait(400);
				clickInventoryItem(body, "Wear");
				wait(400);
				clickInventoryItem(legs, "Wear");
				wait(400);
				clickInventoryItem(weapon, "Wear");
				wait(400);
			} catch (Exception e) {

			}
		}
		return;
	}

	public void activatePrayer() {
		if (getCurrentTab() != TAB_PRAYER) {
			openTab(TAB_PRAYER);
		}
		if (Piety) {
			log("Piety Activated!");
			atInterface(RSInterface.getInterface(271).getChild(57));
			wait(random(200, 500));
		}
		if (Chivalry) {
			log("Chivalry Activated!");
			atInterface(RSInterface.getInterface(271).getChild(55));
			wait(random(200, 500));
		}
		if (MysticMight) {
			log("Mystic Might Activated!");
			atInterface(RSInterface.getInterface(271).getChild(45));
			wait(random(200, 500));
		}
		if (EagleEye) {
			log("Eagle Eye Activated!");
			atInterface(RSInterface.getInterface(271).getChild(43));
			wait(random(200, 500));
		}
		if (IncredibleReflexes) {
			log("Incredible Reflexes Activated!");
			atInterface(RSInterface.getInterface(271).getChild(35));
			wait(random(200, 500));
		}
		if (UltimateStrength) {
			log("Ultimate Strength Activated!");
			atInterface(RSInterface.getInterface(271).getChild(33));
			wait(random(200, 500));
		}
	}

	public void originalArmourOn() {
		if (inventoryContainsAny(helm, weapon, body, shield, legs)) {
			if (getCurrentTab() != TAB_INVENTORY) {
				openTab(TAB_INVENTORY);
			}
			wait(random(600, 1200));
			try {
				openTab(Constants.TAB_INVENTORY);
				clickInventoryItem(helm, "Wear");
				wait(400);
				clickInventoryItem(shield, "Wear");
				wait(400);
				clickInventoryItem(body, "Wear");
				wait(400);
				clickInventoryItem(legs, "Wear");
				wait(400);
				clickInventoryItem(weapon, "Wear");
				wait(400);
			} catch (Exception e) {

			}
		}
		return;
	}

	// Method for clicking an inventoryItem
	public boolean clickInventoryItem(int itemID, String option) {
		if (getCurrentTab() != TAB_INVENTORY) {
			openTab(TAB_INVENTORY);
		}
		int[] items = getInventoryArray();
		java.util.List<Integer> possible = new ArrayList<Integer>();
		for (int i = 0; i < items.length; i++) {
			if (items[i] == itemID) {
				possible.add(i);
			}
		}
		if (possible.size() == 0) {
			return false;
		}
		int idx = possible.get(random(0, possible.size()));
		Point t = getInventoryItemPoint(idx);
		moveMouse(t, 5, 5);
		long waitTime = System.currentTimeMillis() + random(50, 250);
		boolean found = false;
		while (!found && System.currentTimeMillis() < waitTime) {
			wait(15);
			if ((getMenuItems()).get(0).toLowerCase().contains(
					option.toLowerCase())) {
				found = true;
			}
		}
		if (found) {
			clickMouse(true);
			wait(random(150, 250));
			return true;
		}
		clickMouse(false);
		wait(random(150, 250));
		return atMenu(option);
	}

	private boolean inventoryContainsAny(int... items) {
		for (int item : getInventoryArray())
			for (int id : items)
				if (item == id)
					return true;
		return false;
	}

	private boolean equipmentContainsAny(int... items) {
		for (int item : getEquipmentArray())
			for (int id : items)
				if (item == id)
					return true;
		return false;
	}

	// Gets Special
	public int getSpec() {
		return getSetting(300);
	}

	// Gets if Special is Enabled
	public boolean specEnabled() {
		return (getSetting(301)) == 1;
	}

	@Override
	public int loop() {
		int tab1 = getEquipmentArray()[1];
		int tab2 = getEquipmentArray()[2];
		int tab3 = getEquipmentArray()[3];
		int tab4 = getEquipmentArray()[4];
		int tab5 = getEquipmentArray()[5];
		int tab6 = getEquipmentArray()[6];
		int tab7 = getEquipmentArray()[7];
		int tab8 = getEquipmentArray()[8];
		int tab9 = getEquipmentArray()[9];
		int tab10 = getEquipmentArray()[10];
		int tab11 = getEquipmentArray()[11];
		int tab12 = getEquipmentArray()[12];
		int tab13 = getEquipmentArray()[13];
		int tab14 = getEquipmentArray()[14];

		log(Integer.toString(tab1));
		log(Integer.toString(tab2));
		log(Integer.toString(tab3));
		log(Integer.toString(tab4));
		log(Integer.toString(tab5));
		log(Integer.toString(tab6));
		log(Integer.toString(tab7));
		log(Integer.toString(tab8));
		log(Integer.toString(tab9));
		log(Integer.toString(tab10));
		log(Integer.toString(tab11));
		log(Integer.toString(tab12));
		log(Integer.toString(tab13));
		log(Integer.toString(tab14));
		return 200;
	}

}
